package jdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;

public class JDBCDemo9 {
    public static void main(String[] args) {
        try (Connection connection = DBUtil.getConnection();) {
            connection.setAutoCommit(false);
            String sql="INSERT INTO user(username,password,nickname,age)"+
                       "VALUES(?,?,?,?)";
            PreparedStatement preparedStatement = connection.prepareStatement(sql);
            preparedStatement.setString(1, "admin");
            preparedStatement.setString(2, "123456");
            preparedStatement.setString(3, "管理员");
            preparedStatement.setInt(4, 18);
            int num=preparedStatement.executeUpdate();
            System.out.println(num>0?"注册成功!":"添加失败!");
            connection.commit();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
